package com.example.demo.mapper;

import com.example.demo.bean.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface MessageMapper {
    @Insert("INSERT INTO message(industry_id, goods_weight, destination, goods_weight_remain, record_id) " +
            "VALUES(#{message.industry_id}, #{message.goods_weight}, #{message.destination}, #{message.goods_weight}, #{message.record_id})")
    void addMessage(@Param("message") Message message);

    @Select("select message_id,industry_id,goods_weight,goods_weight_remain,destination from message where done_or_not = 0 and can_be_done != 1")
    List<Message> getMessages();

    @Update("update message set cost = cost + #{cost} where message_id = #{message_id}")
    void changeMessage(@Param("message_id") int message_id, @Param("cost") double cost);

    @Select("select message_id,industry_id,destination from message where done_or_not = 0 and can_be_done = 1")
    List<Map<String,Object>> queryMessages();

    @Update("update message set can_be_done = 1 where message_id = #{message_id}")
    void setCan_be_done1(@Param("message_id") int message_id);

    @Update("update message set can_be_done = 0 where message_id = #{message_id}")
    void setCan_be_done0(@Param("message_id") int message_id);

    @Select("select can_be_done from message where done_or_not = 0")
    List<Map<String,Object>> messageCharge();

    @Select("select goods_weight_remain from message where message_id= #{message_id}")
    double getRemain(@Param("message_id") int message_id);

    @Update("update message set goods_weight_remain = goods_weight_remain - #{goods} where message_id = #{message_id}")
    void changeRemain(@Param("message_id") int message_id,@Param("goods") double goods);

    @Update("update message set done_or_not = 1 where message_id = #{message_id}")
    void setMessage(@Param("message_id") int message_id);

    @Select("select cost from message where message_id = #{message_id}")
    double findCost(@Param("message_id") int message_id);

    @Select("select industry_id from message where message_id = #{message_id}")
    int get_industry(@Param("message_id") int message_id);

    @Update("update message set empty_distance = empty_distance + #{empty_distance} where message_id = #{message_id}")
    void setEmptyDistance(@Param("message_id") int message_id,@Param("empty_distance") double empty_distance);

    @Select("select message_id,empty_distance,cost from message where record_id = #{record_id}")
    List<Map<String,Object>> get_message_message(@Param("record_id") int record_id);

    @Select("select destination from message where message_id = #{message_id}")
    int select_end(@Param("message_id") int message_id);
}
